import { forwardRef, HttpModule, MiddlewareConsumer, Module, NestModule } from '@nestjs/common';
import { TypeOrmModule } from '@nestjs/typeorm';
import { UserActivityLoggerMiddleware } from '../../middlewares/user-activity-logger.middleware';
import { OrganizationModule } from '../organization/organization.module';
import { RoleModule } from '../role/role.module';
import { UserAdminController } from './controllers/admin/user.admin.controller';
import { UserEntity } from './entities/user.entity';
import { AuthService } from './services/auth.service';
import { UserService } from './services/user.service';
import { UserUtil } from './utils/user.util';

@Module({
  imports: [TypeOrmModule.forFeature([UserEntity]), HttpModule, OrganizationModule, forwardRef(() => RoleModule)],
  controllers: [UserAdminController],
  providers: [UserService, AuthService, UserUtil],
  exports: [UserService, AuthService]
})
export class UserModule implements NestModule {
  configure(consumer: MiddlewareConsumer) {
    consumer.apply(UserActivityLoggerMiddleware).forRoutes(UserAdminController);
  }
}
